rm(list=ls())

#install packages first if not already installed
library(foreign)
library(readstata13)
library(dplyr)
library(ggplot2)
library(stargazer)
library(dotwhisker)
 
#set working directory
#setwd("~/Dropbox/Coronavirus Nigeria/Analysis/replication")

#read in replication data
lts <-  read.csv("replicationdata.csv")

#####
#####
##### clean data
#####
#####

lts$covidinfo_cure_numeric <- lts$covidinfo_cure
levels(lts$covidinfo_cure_numeric) <- c(levels(lts$covidinfo_cure_numeric), 0,1)
lts$covidinfo_cure_numeric[lts$covidinfo_cure_numeric == "Don't know"] <- 0
lts$covidinfo_cure_numeric[lts$covidinfo_cure_numeric == "Yes"] <- 1
lts$covidinfo_cure_numeric[lts$covidinfo_cure_numeric == "No"] <- 0
lts$covidinfo_cure_numeric <- as.numeric(as.character(lts$covidinfo_cure_numeric))

lts$covidinfo_cure_numeric_dk <- lts$covidinfo_cure
levels(lts$covidinfo_cure_numeric_dk) <- c(levels(lts$covidinfo_cure_numeric_dk), 0,.5,1)
lts$covidinfo_cure_numeric_dk[lts$covidinfo_cure_numeric_dk == "Don't know"] <- 0.5
lts$covidinfo_cure_numeric_dk[lts$covidinfo_cure_numeric_dk == "Yes"] <- 1
lts$covidinfo_cure_numeric_dk[lts$covidinfo_cure_numeric_dk == "No"] <- 0
lts$covidinfo_cure_numeric_dk <- as.numeric(as.character(lts$covidinfo_cure_numeric_dk))

lts$info_supporter_binary <- lts$info_supporter
levels(lts$info_supporter_binary) <- c(levels(lts$info_supporter_binary), 0,1)
lts$info_supporter_binary[lts$info_supporter_binary == "Don't know"] <- 0
lts$info_supporter_binary[lts$info_supporter_binary == "Ruling party"] <- 1
lts$info_supporter_binary[lts$info_supporter_binary == "Opposition party"] <- 0
lts$info_supporter_binary[lts$info_supporter_binary == "Other, please describe"] <- 0
lts$info_supporter_binary[lts$info_supporter_binary == "Refuse to answer"] <- 0
lts$info_supporter_binary <- as.numeric(as.character(lts$info_supporter_binary))

lts$info_supporter_threecat <- lts$info_supporter
lts$info_supporter_threecat <- as.character(lts$info_supporter_threecat)
lts$info_supporter_threecat[lts$info_supporter_threecat == "Don't know"] <- "other"
lts$info_supporter_threecat[lts$info_supporter_threecat == "Ruling party"] <- "rulingparty"
lts$info_supporter_threecat[lts$info_supporter_threecat == "Opposition party"] <- "mainoppositionparty"
lts$info_supporter_threecat[lts$info_supporter_threecat == "Other, please describe"] <- "other"
lts$info_supporter_threecat[lts$info_supporter_threecat == "Refuse to answer"] <- "other"
lts$info_supporter_threecat <- as.factor(lts$info_supporter_threecat)

lts$covidinfo_labmyth_numeric <- lts$covidinfo_labmyth
levels(lts$covidinfo_labmyth_numeric) <- c(levels(lts$covidinfo_labmyth_numeric), 0,1)
lts$covidinfo_labmyth_numeric[lts$covidinfo_labmyth_numeric == "Was developed intentionally in a lab"] <- 1
lts$covidinfo_labmyth_numeric[lts$covidinfo_labmyth_numeric == "Was made accidentally in a lab"] <- 0
lts$covidinfo_labmyth_numeric[lts$covidinfo_labmyth_numeric == "Came about naturally"] <- 0
lts$covidinfo_labmyth_numeric[lts$covidinfo_labmyth_numeric == "Don't know"] <- 0
lts$covidinfo_labmyth_numeric[lts$covidinfo_labmyth_numeric == "Doesn't really exist"] <- 0
lts$covidinfo_labmyth_numeric[lts$covidinfo_labmyth_numeric == "Other"] <- 0
lts$covidinfo_labmyth_numeric <- as.numeric(as.character(lts$covidinfo_labmyth_numeric))

lts$covidinfo_labmyth_numeric_dk <- lts$covidinfo_labmyth
levels(lts$covidinfo_labmyth_numeric_dk) <- c(levels(lts$covidinfo_labmyth_numeric_dk), 0,.5,1)
lts$covidinfo_labmyth_numeric_dk[lts$covidinfo_labmyth_numeric_dk == "Was developed intentionally in a lab"] <- 1
lts$covidinfo_labmyth_numeric_dk[lts$covidinfo_labmyth_numeric_dk == "Was made accidentally in a lab"] <- 0
lts$covidinfo_labmyth_numeric_dk[lts$covidinfo_labmyth_numeric_dk == "Came about naturally"] <- 0
lts$covidinfo_labmyth_numeric_dk[lts$covidinfo_labmyth_numeric_dk == "Don't know"] <- 0.5
lts$covidinfo_labmyth_numeric_dk[lts$covidinfo_labmyth_numeric_dk == "Doesn't really exist"] <- 0
lts$covidinfo_labmyth_numeric_dk[lts$covidinfo_labmyth_numeric_dk == "Other"] <- 0
lts$covidinfo_labmyth_numeric_dk <- as.numeric(as.character(lts$covidinfo_labmyth_numeric_dk))

lts$gender_numeric <- lts$i8_gender
levels(lts$gender_numeric) <- c(levels(lts$gender_numeric), 0,1)
lts$gender_numeric[lts$gender_numeric == "Male"] <- 1
lts$gender_numeric[lts$gender_numeric == "Female"] <- 0
lts$gender_numeric <- as.numeric(as.character(lts$gender_numeric))

lts$covidinfo_gates_numeric <- lts$covidinfo_gates
levels(lts$covidinfo_gates_numeric) <- c(levels(lts$covidinfo_gates_numeric), 0,1)
lts$covidinfo_gates_numeric[lts$covidinfo_gates_numeric == "Don't know"] <- 0
lts$covidinfo_gates_numeric[lts$covidinfo_gates_numeric == "Don't understand the question"] <- 0
lts$covidinfo_gates_numeric[lts$covidinfo_gates_numeric == "Yes"] <- 1
lts$covidinfo_gates_numeric[lts$covidinfo_gates_numeric == "No"] <- 0
lts$covidinfo_gates_numeric[lts$covidinfo_gates_numeric == "Refuse to answer"] <- 0
lts$covidinfo_gates_numeric <- as.numeric(as.character(lts$covidinfo_gates_numeric))

lts$covidinfo_gates_numeric_dk <- lts$covidinfo_gates
levels(lts$covidinfo_gates_numeric_dk) <- c(levels(lts$covidinfo_gates_numeric_dk), 0,.5,1)
lts$covidinfo_gates_numeric_dk[lts$covidinfo_gates_numeric_dk == "Don't know"] <- 0.5
lts$covidinfo_gates_numeric_dk[lts$covidinfo_gates_numeric_dk == "Don't understand the question"] <- 0
lts$covidinfo_gates_numeric_dk[lts$covidinfo_gates_numeric_dk == "Yes"] <- 1
lts$covidinfo_gates_numeric_dk[lts$covidinfo_gates_numeric_dk == "No"] <- 0
lts$covidinfo_gates_numeric_dk[lts$covidinfo_gates_numeric_dk == "Refuse to answer"] <- 0
lts$covidinfo_gates_numeric_dk <- as.numeric(as.character(lts$covidinfo_gates_numeric_dk))

lts$info_symptoms_numeric <- lts$info_symptoms
levels(lts$info_symptoms_numeric) <- c(levels(lts$info_symptoms_numeric), 0,1)
lts$info_symptoms_numeric[lts$info_symptoms_numeric == "Don't know"] <- 0
lts$info_symptoms_numeric[lts$info_symptoms_numeric == "Don't understand the question"] <- 0
lts$info_symptoms_numeric[lts$info_symptoms_numeric == "Yes"] <- 1
lts$info_symptoms_numeric[lts$info_symptoms_numeric == "No"] <- 0
lts$info_symptoms_numeric[lts$info_symptoms_numeric == "Refuse to answer"] <- 0
lts$info_symptoms_numeric <- as.numeric(as.character(lts$info_symptoms_numeric))

lts$info_symptoms_numeric_dk <- lts$info_symptoms
levels(lts$info_symptoms_numeric_dk) <- c(levels(lts$info_symptoms_numeric_dk), 0,.5,1)
lts$info_symptoms_numeric_dk[lts$info_symptoms_numeric_dk == "Don't know"] <- 0.5
lts$info_symptoms_numeric_dk[lts$info_symptoms_numeric_dk == "Don't understand the question"] <- 0
lts$info_symptoms_numeric_dk[lts$info_symptoms_numeric_dk == "Yes"] <- 1
lts$info_symptoms_numeric_dk[lts$info_symptoms_numeric_dk == "No"] <- 0
lts$info_symptoms_numeric_dk[lts$info_symptoms_numeric_dk == "Refuse to answer"] <- 0
lts$info_symptoms_numeric_dk <- as.numeric(as.character(lts$info_symptoms_numeric_dk))

lts$info_prezmd_belief_numeric <- lts$info_prezmd_belief
levels(lts$info_prezmd_belief_numeric) <- c(levels(lts$info_prezmd_belief_numeric), 0,1)
lts$info_prezmd_belief_numeric[lts$info_prezmd_belief_numeric == "Yes"] <- 1
lts$info_prezmd_belief_numeric[lts$info_prezmd_belief_numeric == "No"] <- 0
lts$info_prezmd_belief_numeric[lts$info_prezmd_belief_numeric == "Don't know"] <- 0
lts$info_prezmd_belief_numeric <- as.numeric(as.character(lts$info_prezmd_belief_numeric))

lts$info_prezmd_belief_numeric_dk <- lts$info_prezmd_belief
levels(lts$info_prezmd_belief_numeric_dk) <- c(levels(lts$info_prezmd_belief_numeric_dk), 0,.5,1)
lts$info_prezmd_belief_numeric_dk[lts$info_prezmd_belief_numeric_dk == "Yes"] <- 1
lts$info_prezmd_belief_numeric_dk[lts$info_prezmd_belief_numeric_dk == "No"] <- 0
lts$info_prezmd_belief_numeric_dk[lts$info_prezmd_belief_numeric_dk == "Don't know"] <- 0.5
lts$info_prezmd_belief_numeric_dk <- as.numeric(as.character(lts$info_prezmd_belief_numeric_dk))

lts$info_almajiris_numeric <- lts$info_almajiris
levels(lts$info_almajiris_numeric) <- c(levels(lts$info_almajiris_numeric), 0,1)
lts$info_almajiris_numeric[lts$info_almajiris_numeric == "Don't know"] <- 0
lts$info_almajiris_numeric[lts$info_almajiris_numeric == "Don't understand the question"] <- 0
lts$info_almajiris_numeric[lts$info_almajiris_numeric == "Refuse to answer"] <- 0
lts$info_almajiris_numeric[lts$info_almajiris_numeric == "Yes"] <- 1
lts$info_almajiris_numeric[lts$info_almajiris_numeric == "No"] <- 0
lts$info_almajiris_numeric <- as.numeric(as.character(lts$info_almajiris_numeric))

lts$info_almajiris_numeric_dk <- lts$info_almajiris
levels(lts$info_almajiris_numeric_dk) <- c(levels(lts$info_almajiris_numeric_dk), 0,.5,1)
lts$info_almajiris_numeric_dk[lts$info_almajiris_numeric_dk == "Don't know"] <- 0.5
lts$info_almajiris_numeric_dk[lts$info_almajiris_numeric_dk == "Don't understand the question"] <- 0
lts$info_almajiris_numeric_dk[lts$info_almajiris_numeric_dk == "Refuse to answer"] <- 0
lts$info_almajiris_numeric_dk[lts$info_almajiris_numeric_dk == "Yes"] <- 1
lts$info_almajiris_numeric_dk[lts$info_almajiris_numeric_dk == "No"] <- 0
lts$info_almajiris_numeric_dk <- as.numeric(as.character(lts$info_almajiris_numeric_dk))

lts$i6_religion_numeric <- lts$i6_religion
levels(lts$i6_religion_numeric) <- c(levels(lts$i6_religion_numeric), 0,1)
lts$i6_religion_numeric[lts$i6_religion_numeric == "Other"] <- 0
lts$i6_religion_numeric[lts$i6_religion_numeric == "Christian"] <- 0
lts$i6_religion_numeric[lts$i6_religion_numeric == "Muslim"] <- 1
lts$i6_religion_numeric <- as.numeric(as.character(lts$i6_religion_numeric))

#update age, as we collected this variable in 2016 
lts$age_updated <- lts$age + 6

lts$get_vaccine_numeric <- lts$get_vaccine
levels(lts$get_vaccine_numeric) <- c(levels(lts$get_vaccine_numeric), 0,0.25,0.5, 0.75,1)
lts$get_vaccine_numeric[lts$get_vaccine_numeric == "Definitely not"] <- 0
lts$get_vaccine_numeric[lts$get_vaccine_numeric == "Probably not"] <- 0.25
lts$get_vaccine_numeric[lts$get_vaccine_numeric == "Don't know"] <- 0.5
lts$get_vaccine_numeric[lts$get_vaccine_numeric == "Probably"] <- 0.75
lts$get_vaccine_numeric[lts$get_vaccine_numeric == "Definitely"] <- 1
lts$get_vaccine_numeric[lts$get_vaccine_numeric == "Refuse"] <- NA
lts$get_vaccine_numeric <- as.numeric(as.character(lts$get_vaccine_numeric))

lts$info_prezmd_certainty_numeric<- lts$info_prezmd_certainty
levels(lts$info_prezmd_certainty_numeric) <- c(levels(lts$info_prezmd_certainty_numeric), 0,0.33,0.66,1)
lts$info_prezmd_certainty_numeric[lts$info_prezmd_certainty_numeric == "Not at all sure"] <- 0
lts$info_prezmd_certainty_numeric[lts$info_prezmd_certainty_numeric == "Not too sure"] <- 0.33
lts$info_prezmd_certainty_numeric[lts$info_prezmd_certainty_numeric == "Somewhat sure"] <- 0.66
lts$info_prezmd_certainty_numeric[lts$info_prezmd_certainty_numeric == "Very sure"] <- 1
lts$info_prezmd_certainty_numeric <- as.numeric(as.character(lts$info_prezmd_certainty_numeric))

lts$covidinfo_cure_confidence_numeric<- lts$covidinfo_cure_confidence
levels(lts$covidinfo_cure_confidence_numeric) <- c(levels(lts$covidinfo_cure_confidence_numeric), 0,0.33,0.66,1)
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Not at all sure"] <- 0
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Not too sure"] <- 0.33
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Somewhat sure"] <- 0.66
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Very sure"] <- 1
lts$covidinfo_cure_confidence_numeric <- as.numeric(as.character(lts$covidinfo_cure_confidence_numeric))

lts$info_almajiris_certainty_numeric<- lts$info_almajiris_certainty
levels(lts$info_almajiris_certainty_numeric) <- c(levels(lts$info_almajiris_certainty_numeric), 0,0.33,0.66,1)
lts$info_almajiris_certainty_numeric[lts$info_almajiris_certainty_numeric == "Not at all sure"] <- 0
lts$info_almajiris_certainty_numeric[lts$info_almajiris_certainty_numeric == "Not too sure"] <- 0.33
lts$info_almajiris_certainty_numeric[lts$info_almajiris_certainty_numeric == "Somewhat sure"] <- 0.66
lts$info_almajiris_certainty_numeric[lts$info_almajiris_certainty_numeric == "Very sure"] <- 1
lts$info_almajiris_certainty_numeric <- as.numeric(as.character(lts$info_almajiris_certainty_numeric))

lts$covidinfo_labmyth_confidence_numeric<- lts$covidinfo_labmyth_confidence
levels(lts$covidinfo_labmyth_confidence_numeric) <- c(levels(lts$covidinfo_labmyth_confidence_numeric), 0,0.33,0.66,1)
lts$covidinfo_labmyth_confidence_numeric[lts$covidinfo_labmyth_confidence_numeric == "Not at all sure"] <- 0
lts$covidinfo_labmyth_confidence_numeric[lts$covidinfo_labmyth_confidence_numeric == "Not too sure"] <- 0.33
lts$covidinfo_labmyth_confidence_numeric[lts$covidinfo_labmyth_confidence_numeric == "Somewhat sure"] <- 0.66
lts$covidinfo_labmyth_confidence_numeric[lts$covidinfo_labmyth_confidence_numeric == "Very sure"] <- 1
lts$covidinfo_labmyth_confidence_numeric <- as.numeric(as.character(lts$covidinfo_labmyth_confidence_numeric))

lts$covidinfo_cure_confidence_numeric<- lts$covidinfo_cure_confidence
levels(lts$covidinfo_cure_confidence_numeric) <- c(levels(lts$covidinfo_cure_confidence_numeric), 0,0.33,0.66,1)
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Not at all sure"] <- 0
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Not too sure"] <- 0.33
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Somewhat sure"] <- 0.66
lts$covidinfo_cure_confidence_numeric[lts$covidinfo_cure_confidence_numeric == "Very sure"] <- 1
lts$covidinfo_cure_confidence_numeric <- as.numeric(as.character(lts$covidinfo_cure_confidence_numeric))

#5g
lts$info_certainty_numeric<- lts$info_certainty
levels(lts$info_certainty_numeric) <- c(levels(lts$info_certainty_numeric), 0,0.33,0.66,1)
lts$info_certainty_numeric[lts$info_certainty_numeric == "Not at all sure"] <- 0
lts$info_certainty_numeric[lts$info_certainty_numeric == "Not too sure"] <- 0.33
lts$info_certainty_numeric[lts$info_certainty_numeric == "Somewhat sure"] <- 0.66
lts$info_certainty_numeric[lts$info_certainty_numeric == "Very sure"] <- 1
lts$info_certainty_numeric <- as.numeric(as.character(lts$info_certainty_numeric))

lts$info_gates_certainty_numeric<- lts$info_gates_certainty
levels(lts$info_gates_certainty_numeric) <- c(levels(lts$info_gates_certainty_numeric), 0,0.33,0.66,1)
lts$info_gates_certainty_numeric[lts$info_gates_certainty_numeric == "Not at all sure"] <- 0
lts$info_gates_certainty_numeric[lts$info_gates_certainty_numeric == "Not too sure"] <- 0.33
lts$info_gates_certainty_numeric[lts$info_gates_certainty_numeric == "Somewhat sure"] <- 0.66
lts$info_gates_certainty_numeric[lts$info_gates_certainty_numeric == "Very sure"] <- 1
lts$info_gates_certainty_numeric <- as.numeric(as.character(lts$info_gates_certainty_numeric))

lts$social_media <- lts$covidinfo_media
levels(lts$social_media) <- c(levels(lts$social_media), 0,1)
lts$social_media[lts$social_media == "SMS"] <- 1
lts$social_media[lts$social_media == "Whatsapp"] <- 1
lts$social_media[lts$social_media == "Facebook"] <- 1
lts$social_media[lts$social_media == "Twitter"] <- 1
lts$social_media[lts$social_media == "Television"] <- 0
lts$social_media[lts$social_media == "Radio"] <- 0
lts$social_media[lts$social_media == "Newspaper"] <- 0
lts$social_media[lts$social_media == "None"] <- NA
lts$social_media[lts$social_media == "Other"] <- NA
lts$social_media <- as.numeric(as.character(lts$social_media))

#change reference categories 
lts$info_supporter_threecat <- as.factor(lts$info_supporter_threecat)
lts <- within(lts, info_supporter_threecat <- relevel(info_supporter_threecat, ref = "rulingparty"))

lts$info_prezmd_belief <- as.factor(lts$info_prezmd_belief)
lts <- within(lts, info_prezmd_belief <- relevel(info_prezmd_belief, ref = "No"))

lts$info_almajiris <- as.factor(lts$info_almajiris)
lts <- within(lts, info_almajiris <- relevel(info_almajiris, ref = "No"))

lts$covidinfo_labmyth <- as.factor(lts$covidinfo_labmyth)
lts <- within(lts, covidinfo_labmyth <- relevel(covidinfo_labmyth, ref = "Came about naturally"))

lts$covidinfo_cure <- as.factor(lts$covidinfo_cure)
lts <- within(lts, covidinfo_cure <- relevel(covidinfo_cure, ref = "No"))

lts$info_symptoms <- as.factor(lts$info_symptoms)
lts <- within(lts, info_symptoms <- relevel(info_symptoms, ref = "No"))

lts$covidinfo_gates <- as.factor(lts$covidinfo_gates)
lts <- within(lts, covidinfo_gates <- relevel(covidinfo_gates, ref = "No"))

#make age binary, above/below median age
median(na.omit(lts$age_updated))
lts$age_binary <- NA
lts$age_binary[lts$age_updated < 44] <- 0
lts$age_binary[lts$age_updated > 43] <- 1

#####
#####
##### analysis
#####
#####

#####
##### summary statistics
#####

lts$participated_round_4 <- "no"
lts$participated_round_4[lts$wave1 =="yes"] <- "yes"
lts$participated_round_4[lts$wave2 =="yes"] <- "yes"
lts$participated_round_4[lts$wave3 =="yes"] <- "yes"
lts$participated_round_4[lts$wave4 =="yes"] <- "yes"

lts_participated_round_4 <- subset(lts, lts$participated_round_4=="yes")

myvars <- c("age_updated", "igbo", "gender_numeric", "postsecondary", "social_media", "info_supporter_binary", 
            "info_prezmd_belief_numeric", "covidinfo_cure_numeric","info_almajiris_numeric", "covidinfo_labmyth_numeric",
            "covidinfo_gates_numeric", "info_symptoms_numeric","get_vaccine_numeric")

lts_participated_round_4_small <- lts_participated_round_4[myvars]

#Appendix A.6 (table 1 in the appendix)
stargazer(lts_participated_round_4_small, omit.summary.stat = c("p25", "p75"), covariate.labels = c("Age","Igbo","Male",
                "Any postsecondary education","Social media primary COVID info. source","Support ruling party",
                "Believe Madagascar misinfo.", "Believe cure misinfo.","Believe almajiri misinfo.",
                "Believe COVID created intentionally in lab misinfo.",
                "Believe Gates misinfo.","Believe 5g misinfo.","Willing to get vaccine"))

#####
##### strength of belief
#####

#Appendix A.6 (table 3 in the appendix)
conf1 <- lm(info_prezmd_certainty_numeric ~ info_prezmd_belief_numeric, data=lts) #no relationship
conf2 <- lm(info_almajiris_certainty_numeric ~ info_almajiris_numeric, data=lts) #no relationship
conf3 <- lm(covidinfo_labmyth_confidence_numeric ~ covidinfo_labmyth_numeric, data=lts) #no relationship
conf4 <- lm(covidinfo_cure_confidence_numeric ~ covidinfo_cure_numeric, data=lts)
conf5 <- lm(info_certainty_numeric ~ info_symptoms_numeric, data=lts)
conf6 <- lm(info_gates_certainty_numeric ~ covidinfo_gates_numeric, data=lts)

stargazer(conf1, conf2, conf3, conf4, conf5, conf6,
          dep.var.labels=c("Certainty"),
          covariate.labels = c("Madagascar","Almajiris","Lab",
                               "Cure","5G","Gates"))

#Appendix A.6 (table 2 in the appendix)
prop.table(table(lts$info_prezmd_belief, lts$info_prezmd_certainty), margin=1)

prop.table(table(lts$info_almajiris, lts$info_almajiris_certainty), margin=1)

prop.table(table(lts$covidinfo_labmyth_numeric, lts$covidinfo_labmyth_confidence), margin=1)

prop.table(table(lts$covidinfo_cure_numeric, lts$covidinfo_cure_confidence), margin=1)

prop.table(table(lts$info_symptoms_numeric, lts$info_certainty), margin=1)

prop.table(table(lts$covidinfo_gates_numeric, lts$info_gates_certainty), margin=1)

#####
##### Among respondents who participated in first three waves of lts4 (last wave 
#asked no misinfo questions), distribution of belief in misinfo
#####

x <- subset(lts, lts$wave1 == "yes")
y <- subset(x, x$wave2 == "yes")
z <- subset(y, y$wave3 == "yes")
first_3_waves <- z

first_3_waves$info_prezmd_belief_numericx <- first_3_waves$info_prezmd_belief_numeric  
first_3_waves$info_prezmd_belief_numericx[is.na(first_3_waves$info_prezmd_belief_numericx)] <- 0

first_3_waves$all_misinfo <- first_3_waves$covidinfo_gates_numeric + first_3_waves$info_symptoms_numeric + 
  first_3_waves$covidinfo_labmyth_numeric + first_3_waves$covidinfo_cure_numeric + 
  first_3_waves$info_almajiris_numeric + first_3_waves$info_prezmd_belief_numericx

prop.table(table(first_3_waves$all_misinfo))

first_3_waves %>% 
  count(all_misinfo) %>% 
  mutate(perc = n / nrow(first_3_waves)) -> first_3_wavesx

first_3_waves <- as.data.frame(first_3_waves)


#Appendix A.11 (table 5 in the appendix)
#combine all misinfo, look at correlates
reg1 <- lm(all_misinfo ~ info_supporter_threecat + igbo + postsecondary + male + 
             age_updated+ social_media, data=first_3_waves)
stargazer(reg1,  dep.var.labels=c("Belief in all Misinformation (0-6)"),
          covariate.labels=c("Opposition party supporter", "Third party supporter","Igbo",
                                   "Postsecondary education", "Male", "Age", "Social media"),
          font.size="scriptsize")


#####
##### WILLINGNESS TO GET VACCINE
#####

regv1 <- lm(get_vaccine_numeric ~ lts$covidinfo_gates_numeric + info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)
regv2 <- lm(get_vaccine_numeric ~ lts$info_symptoms_numeric + info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)
regv3 <- lm(get_vaccine_numeric ~ lts$covidinfo_labmyth_numeric + info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)
regv4 <- lm(get_vaccine_numeric ~ lts$covidinfo_cure_numeric + info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)
regv5 <- lm(get_vaccine_numeric ~ lts$info_almajiris_numeric + info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)
regv6 <- lm(get_vaccine_numeric ~ lts$info_prezmd_belief_numeric + info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)

#Appendix A.12 (table 6 in the appendix)
stargazer(regv1, regv2, regv3, regv4, regv5, regv6, 
covariate.labels=c("Gates","5G","Lab","Cure","Almajiris","Madagascar",
                                                "Opposition party supporter","Third party supporter",
                                               "Igbo","Postsecondary education","Male","Age","Social media"),
                                               dep.var.labels=c("Willing to Get Vaccine"),
          column.sep.width = "-10pt")

#Appendix A.13 (table 8 in the appendix)
regv7 <- lm(get_vaccine_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)

stargazer(regv7, 
          covariate.labels=c("Opposition party supporter","Third party supporter",
                             "Igbo","Postsecondary education","Male","Age","Social media"),
          dep.var.labels=c("Willing to Get Vaccine"),
          column.sep.width = "-10pt")


#####
##### dot whisker plots
#####

lts$age_updated <- as.numeric(lts$age_updated)

m1 <- lm(covidinfo_gates_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)
m2 <- lm(info_symptoms_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m3 <- lm(covidinfo_labmyth_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m4 <- lm(covidinfo_cure_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m5 <- lm(info_prezmd_belief_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m6 <- lm(info_almajiris_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m7 <- lm(get_vaccine_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)

#same as above, but using coding where "don't know" for misinfo is 0.5
m1dk <- lm(covidinfo_gates_numeric_dk ~ info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media, data=lts)
m2dk <- lm(info_symptoms_numeric_dk ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m3dk <- lm(covidinfo_labmyth_numeric_dk ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m4dk <- lm(covidinfo_cure_numeric_dk ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m5dk <- lm(info_prezmd_belief_numeric_dk ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)
m6dk <- lm(info_almajiris_numeric_dk ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=lts)

#Figure 4 (main paper)

#vaccine dot whiskers
#pdf(file="~/Dropbox/Coronavirus Nigeria/figures/dotwhiskers-vaccine.pdf", width=12)
dwplot(list(m7), show_intercept = TRUE,
       dot_args = list(size = 3.2),
       whisker_args = list(size = 1),
       vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2)) %>% 
  relabel_predictors(c(info_supporter_threecatmainoppositionparty="Partisanship: Main opp. party",
                       info_supporter_threecatother="Partisanship: Other",
                       igbo = "Igbo",                       
                       postsecondary = "Postsecondary education", 
                       male = "Male", 
                       age_binary = "Age",
                       social_media="Social media")) +
  theme_bw() + xlab("Coefficient Estimate") + ylab("") + 
  theme(text = element_text(size=30)) +
  scale_colour_discrete(name = "Model", labels = c("Willingness to \nget vaccine"))
#dev.off()

#Figure 3 (main paper)
#dot whiskers cure
#pdf(file="~/Dropbox/Coronavirus Nigeria/figures/dotwhiskers-cure.pdf", width=13)
dwplot(list(m4, m5),
       dot_args = list(size = 3.2),
       whisker_args = list(size = 1),
       vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2)) %>% 
  relabel_predictors(c(info_supporter_threecatmainoppositionparty="Partisanship: Main opp. party",
                       info_supporter_threecatother="Partisanship: Other",
                       igbo = "Igbo",                       
                       postsecondary = "Postsecondary education", 
                       male = "Male", 
                       age_binary = "Age",
                       social_media="Social media")) +
  scale_colour_discrete(name = "Model", labels = c("Cure","Madagascar"), 
                      guide = guide_legend(reverse = TRUE)) + 
  xlim(-.22,.35) + 
  ggtitle("Cure Misinformation") + 
  theme_bw() + xlab("Coefficient Estimate") + ylab("") + 
  theme(text = element_text(size=30)) 
#dev.off()


#Appendix A.10 (figure 6 in the appendix)
#dot whiskers cure - coding don't know as 0.5
#pdf(file="~/Dropbox/Coronavirus Nigeria/figures/dotwhiskers-cure-dk.pdf", width=13)
dwplot(list(m4dk, m5dk),
       dot_args = list(size = 3.2),
       whisker_args = list(size = 1),
       vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2)) %>% 
  relabel_predictors(c(info_supporter_threecatmainoppositionparty="Partisanship: Main opp. party",
                       info_supporter_threecatother="Partisanship: Other",
                       igbo = "Igbo",                       
                       postsecondary = "Postsecondary education", 
                       male = "Male", 
                       age_binary = "Age",
                       social_media="Social media")) +
  scale_colour_discrete(name = "Model", labels = c("Cure","Madagascar"), 
                        guide = guide_legend(reverse = TRUE)) + 
  xlim(-.22,.35) + 
  ggtitle("Cure Misinformation") + 
  theme_bw() + xlab("Coefficient Estimate") + ylab("") + 
  theme(text = element_text(size=30)) 
#dev.off()

#Figure 2 (main paper)
#dot whiskers anti-government
#pdf(file="~/Dropbox/Coronavirus Nigeria/figures/dotwhiskers-govbad.pdf", width=13)
dwplot(list(m1,m2,m6), 
       dot_args = list(size = 3.2),
       whisker_args = list(size = 1),
       vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2)) %>% 
  relabel_predictors(c(info_supporter_threecatmainoppositionparty="Partisanship: Main opp. party",
                       info_supporter_threecatother="Partisanship: Other",
                       igbo = "Igbo",                       
                       postsecondary = "Postsecondary education", 
                       male = "Male", 
                       age_binary = "Age",
                       social_media="Social media")) +
  scale_colour_discrete(name = "Model", labels = c("Gates","5g","Almajiris"), 
                        guide = guide_legend(reverse = TRUE)) + 
  xlim(-.22,.35) + 
  ggtitle("Anti-Government Misinformation") + 
  theme_bw() + xlab("Coefficient Estimate") + ylab("") + 
  theme(text = element_text(size=30)) 
#dev.off()

#Appendix A.10 (figure 5 in the appendix)
#dot whiskers - coding don't know as 0.5
#pdf(file="~/Dropbox/Coronavirus Nigeria/figures/dotwhiskers-govbad-dk.pdf", width=13)
dwplot(list(m1dk,m2dk,m6dk), 
       dot_args = list(size = 3.2),
       whisker_args = list(size = 1),
       vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2)) %>% 
  relabel_predictors(c(info_supporter_threecatmainoppositionparty="Partisanship: Main opp. party",
                       info_supporter_threecatother="Partisanship: Other",
                       igbo = "Igbo",                       
                       postsecondary = "Postsecondary education", 
                       male = "Male", 
                       age_binary = "Age",
                       social_media="Social media")) +
  scale_colour_discrete(name = "Model", labels = c("Gates","5g","Almajiris"), 
                        guide = guide_legend(reverse = TRUE)) + 
  xlim(-.22,.35) + 
  ggtitle("Anti-Government Misinformation") + 
  theme_bw() + xlab("Coefficient Estimate") + ylab("") + 
  theme(text = element_text(size=30)) 
#dev.off()


#dot whiskers include religion
m1r <- lm(covidinfo_gates_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary + social_media + i6_religion_numeric, data=lts)
m2r <- lm(info_symptoms_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media + i6_religion_numeric, data=lts)
m3r <- lm(covidinfo_labmyth_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media + i6_religion_numeric, data=lts)
m4r <- lm(covidinfo_cure_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media + i6_religion_numeric, data=lts)
m5r <- lm(info_prezmd_belief_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media + i6_religion_numeric, data=lts)
m6r <- lm(info_almajiris_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media + i6_religion_numeric, data=lts)
m7r <- lm(get_vaccine_numeric ~ info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media + i6_religion_numeric, data=lts)

#Appendix A.7 (figure 4 in the appendix)
#pdf(file="~/Dropbox/Coronavirus Nigeria/figures/dotwhiskers-religion.pdf", width=12)
dwplot(list(m1r,m2r,m3r,m4r,m5r,m6r,m7r), show_intercept = TRUE,
       dot_args = list(size = 3.2),
       whisker_args = list(size = 0.8),
       vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2)) %>% 
  relabel_predictors(c(info_supporter_threecatmainoppositionparty="Partisanship: Main opp. party",
                       info_supporter_threecatother="Partisanship: Other",
                       igbo = "Igbo",                       
                       postsecondary = "Postsecondary education", 
                       male = "Male", 
                       age_binary = "Age",
                       social_media="Social media",
                       i6_religion_numeric="Muslim")) +
  theme_bw() + xlab("Coefficient Estimate") + ylab("") + 
  theme(text = element_text(size=30)) +
  scale_colour_discrete(name = "Model", labels = c("Gates","5g","Lab","Cure", 
                                                   "Madagascar","Almajiri","Vaccine"))
#dev.off()



#####
##### LOOK AT CORRELATES OF ANTI-GOVERNMENT MISINFO / CURE
#####

x <- subset(lts, lts$wave2 == "yes")
y <- subset(x, x$wave3 == "yes")

waves_2_3 <- y

waves_2_3$govt_bad_misinfo <- waves_2_3$covidinfo_gates_numeric + waves_2_3$info_symptoms_numeric + 
  waves_2_3$info_almajiris_numeric 

waves_2_3$govt_bad_misinfo_normalized = (waves_2_3$govt_bad_misinfo-min(waves_2_3$govt_bad_misinfo))/(max(waves_2_3$govt_bad_misinfo)-min(waves_2_3$govt_bad_misinfo))

regbad <- lm(govt_bad_misinfo_normalized  ~  info_supporter_threecat + igbo + postsecondary + male + 
             age_binary + social_media, data=waves_2_3)

x <- subset(lts, lts$wave1 == "yes")
y <- subset(x, x$wave3 == "yes")

waves_1_3 <- y

waves_1_3$info_prezmd_belief_numeric[is.na(waves_1_3$info_prezmd_belief_numeric)] <- 0

waves_1_3$cure_misinfo <- waves_1_3$covidinfo_cure_numeric + waves_1_3$info_prezmd_belief_numeric

waves_1_3$cure_misinfo_normalized = (waves_1_3$cure_misinfo-min(waves_1_3$cure_misinfo))/(max(waves_1_3$cure_misinfo)-min(waves_1_3$cure_misinfo))

regcure <- lm(cure_misinfo_normalized  ~  info_supporter_threecat + igbo + postsecondary + male + 
             age_binary + social_media, data=waves_1_3)

#Appendix A.9 (table 4 in the appendix)
stargazer(regbad, regcure, dep.var.labels=c("Anti-Government Misinfo.","Cure Misinfo"), 
          covariate.labels=c("Opposition party supporter", "Third party supporter","Igbo",
                             "Postsecondary education", "Male", "Age", "Social media"),
          font.size="scriptsize")

waves_1_3_4 <- subset(waves_1_3, waves_1_3$wave4=="yes")
summary(lm(get_vaccine_numeric ~ cure_misinfo_normalized + info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=waves_1_3_4))

waves_2_3_4 <- subset(waves_2_3, waves_2_3$wave4=="yes")
summary(lm(get_vaccine_numeric ~ govt_bad_misinfo_normalized + info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=waves_2_3_4))

waves_all <- subset(waves_2_3_4, waves_2_3_4$wave1=="yes")

waves_all$all_misinfo <- waves_all$covidinfo_gates_numeric + waves_all$info_symptoms_numeric + 
  waves_all$covidinfo_labmyth_numeric + waves_all$covidinfo_cure_numeric + 
  waves_all$info_almajiris_numeric + waves_all$info_prezmd_belief_numeric

summary(lm(get_vaccine_numeric ~ all_misinfo, data=waves_all)) 
summary(lm(get_vaccine_numeric ~ all_misinfo + info_supporter_threecat + igbo + postsecondary + male + age_binary+ social_media, data=waves_all)) 

lts$gates_certain <- 0
lts$gates_certain[lts$info_gates_certainty_numeric==1 & lts$covidinfo_gates_numeric==1] <- 1

lts$cure_certain <- 0
lts$cure_certain[lts$covidinfo_cure_confidence_numeric==1 & lts$covidinfo_cure_numeric==1] <- 1

lts$fiveg_certain <- 0
lts$fiveg_certain[lts$info_certainty_numeric==1 & lts$info_symptoms_numeric==1] <- 1

lts$madagascar_certain <- 0
lts$madagascar_certain[lts$info_prezmd_certainty_numeric==1 & lts$info_prezmd_belief_numeric==1] <- 1

lts$lab_certain <- 0
lts$lab_certain[lts$covidinfo_labmyth_numeric==1 & lts$covidinfo_labmyth_numeric==1] <- 1

lts$alm_certain <- 0
lts$alm_certain[lts$info_almajiris_certainty_numeric==1 & lts$info_almajiris_numeric==1] <- 1

s1 <- lm(lts$get_vaccine_numeric ~ lts$madagascar_certain)
s2 <- lm(lts$get_vaccine_numeric ~ lts$alm_certain)
s3 <- lm(lts$get_vaccine_numeric ~ lts$lab_certain)
s4 <- lm(lts$get_vaccine_numeric ~ lts$covidinfo_cure_numeric)
s5 <- lm(lts$get_vaccine_numeric ~ lts$fiveg_certain) 
s6 <- lm(lts$get_vaccine_numeric ~ lts$gates_certain)

#Appendix A.12 (table 7 in the appendix)
stargazer(s1,s2,s3,s4,s5,s6,font.size = "tiny",
          dep.var.labels=c("Willingness to get vaccinated"),
          covariate.labels = c("Madagascar","Almajiris","Lab",
                               "Cure","5G","Gates"),
          omit.stat="f",
          column.sep.width = "-10pt",
          title="Correlation between strongly believing each piece of misinformation (0,1) and willingness to be vaccinated.",
          label="strength")

#Read in two variables from Afrobarometer Nigeria Round 8 - 2021
data2021<-read.csv("Afr82021.csv")

#(Previous question: Do you feel close to any party?) Q91B: Which party is that?

data2021$close<-ifelse(data2021$Q91B==621, "All Progressive Congress",
                       ifelse(data2021$Q91B==638, "People's Democratic Party", "Other/Not Applicable/Refuse"))

#Q41E:How much do you trust each of the following, or haven’t you heard enough about them to say: The Ruling Party?

data2021$Trust_RulingParty<-ifelse(data2021$Q41E==0, 0,
                                   ifelse(data2021$Q41E==1, 33.33,
                                          ifelse(data2021$Q41E==2, 66.66,
                                                 ifelse(data2021$Q41E==3, 100, NA))))

#Appendix A.2 (table 1 in appendix)
m1<-lm(Trust_RulingParty~close, data=data2021)

stargazer(m1, 
          covariate.labels=c("Close: Other (Refused, Don't Know, Missing)", 
                             "Close: People's Democratic Party"))

